package com.vpen.payment.controller;

import com.vpen.commons.pojo.CommonResult;
import com.vpen.commons.pojo.Payment;
import com.vpen.payment.service.PaymentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;



/**
 * @Version 1.0
 * @Author: Vpen
 * @Date: 2021/3/16 19:11
 * @Content:
 */
@Api("订单服务端")
@RestController
public class PaymentController {
    @Resource
    PaymentService paymentService;

    /** 描述: 端口号
     * @date 2021/8/7 22:14
     **/
    @Value("${server.port}")
    private String port;

    /** 描述:
     * @author 韦鹏
     * @name getPayment
     * @date 2021/8/7 22:14
     * @param id
     * @return com.vpen.commons.pojo.CommonResult<com.vpen.commons.pojo.Payment>
     **/
    @ApiOperation("获取订单")
    @GetMapping(value = "/payment/get/{id}")
    public CommonResult<Payment> getPayment(@PathVariable("id") Integer id){
        Payment payment = paymentService.selectPaymentById(id);
        if (payment != null){
            return new CommonResult<>(2000,"成功"+port,payment);
        }else {
            return new CommonResult<>(4000,"失败"+port);
        }
    }
    @ApiOperation("添加订单")
    @PostMapping(value = "/payment/insert")
    public CommonResult<Payment> insertPayment(@RequestBody Payment payment){
        int res = paymentService.creatPayment(payment);
        if (res>0){
            return new CommonResult<>(2000,"成功"+port,payment);
        }
        else {
            return new CommonResult<>(4000,"失败"+port);
        }
    }

}
